import config from '../utils/config.js'
export default {
	login({
		nickName,
		img,
		code,
		cb
	}) {
		uni.request({
			url: `${config['api_server']}/users/login`,
			data: {
				nickName,
				img,
				code
			},
			method: 'GET',
			header: {
				'custom-header': 'hello' //自定义请求头信息
			},
			success: ({
				data
			}) => {
				if (data) {
					uni.setStorage({
						key: 'token',
						data: data.token,
						success: () => {
							cb(data)
						}
					})
				} else {
					cb(false)
				}

			}
		});
	},
	find_by_id: ({
		_id,
		cb
	}) => {
		uni.request({
			url: `${config['api_server']}/users/search`,
			method: 'GET',
			data: {
				_id
			},
			header: {
				'custom-header': 'hello' //自定义请求头信息
			},
			success: ({
				data
			}) => {
				cb(data)
			}
		});
	},
	update_addres({
		_id,
		delivery,
		cb
	}) {
		console.log('delivery=======>', delivery)
		uni.request({
			url: `${config['api_server']}/users/${_id}/address`,
			method: 'PUT',
			data: delivery,
			header: {
				'custom-header': 'hello' //自定义请求头信息
			},
			success: ({
				data
			}) => {
				cb(data)
			}
		})
	}
}
